package com.jr.controller;


import com.google.gson.Gson;
import com.jr.entity.Job;
import com.jr.service.JobService;
import com.jr.service.impl.UserJobEnterpriseServiceImpl;
import com.jr.util.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;


/**
 * 工作表
 *
 * @author Snoopy
 * @since 1.0.0 2022-12-31
 */
@Controller
@SuppressWarnings("all")
public class JobController {
    /**
     * @description: 自动导入
     * @author: 张杨
     * @date: 2023/1/12 10:36
     * @param:
     * @return:
     **/
    @Autowired
    private JobService jobService;
    /**
     * @description: 根据eid查询该企业所有职位
     * @author: 张杨
     * @date: 2023/1/12 10:37
     * @param: [eid]
     * @return: java.util.List<com.jr.entity.Job>
     **/
    @PostMapping(value = "getEnterprisejobs",produces = "application/json;charset=utf-8")
    public @ResponseBody List<Job> getjobs(int eid){
        List<Job> jobList=jobService.selectJobWitheid(eid);
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (Job job:jobList){
            job.setJrefreshdatestr(simpleDateFormat.format(job.getJrefreshdate()));
        }
        return jobList;
    }
    /**
     * @description: 根据Jid查询该职位所对应的职位信息
     * @author: 张杨
     * @date: 2023/1/12 10:38
     * @param: [jid]
     * @return: org.springframework.web.servlet.ModelAndView
     **/
    @GetMapping("getjobbyjid")
    public ModelAndView getjobbyjid(int jid){
        ModelAndView modelAndView=new ModelAndView();
        Job job=jobService.selectJobByjid(jid);

        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        job.setJrefreshdatestr(simpleDateFormat.format(job.getJrefreshdate()));
        modelAndView.addObject("job",job);
        modelAndView.setViewName("job_info.jsp");
        return modelAndView;
    }
    /**
     * @description: 查询所有工作信息
     * @author: 张杨
     * @date: 2023/1/12 10:39
     * @param: []
     * @return: java.lang.String
     **/
    @PostMapping(value = "selectJobAll",produces = "text/html;charset=utf-8")
    public @ResponseBody String selectJobAll(){
        Gson gson = new Gson();
        List<Job> jobAll = jobService.selectJobAll();
        return gson.toJson(jobAll);
    }
}